package com.bnlr.lrparking.adapter;


import android.graphics.Color;
import android.support.annotation.Nullable;
import android.util.SparseArray;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.bnlr.lrparking.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by tian on 2017/9/16.
 */

public class StallDealScreenAdapter extends BaseQuickAdapter<String,BaseViewHolder>{

    private ListClickListener listClickListener;
    private SparseArray<String> sparseArray = new SparseArray<>();
    public StallDealScreenAdapter(@Nullable List<String> data) {
        super(R.layout.item_stallscreen,data);
    }

    public void setListClickListener(ListClickListener listClickListener) {
        this.listClickListener = listClickListener;
    }

    @Override
    protected void convert(final BaseViewHolder helper, final String item) {
        final RelativeLayout rlBg = helper.getView(R.id.rely_screen_bg);
        final TextView tv = helper.getView(R.id.tv_itemscreen);
        tv.setText(item);
        rlBg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (item.equals(sparseArray.get(helper.getAdapterPosition()))) {
                    sparseArray.remove(helper.getAdapterPosition());
                    rlBg.setBackground(mContext.getResources().getDrawable(R.drawable.conversation_item_background_read));
                    tv.setTextColor(mContext.getResources().getColor(R.color.gray_color));
                } else {
                    sparseArray.put(helper.getAdapterPosition(),item);
                    tv.setTextColor(Color.WHITE);
                    rlBg.setBackground(mContext.getResources().getDrawable(R.drawable.select_verifica_format));
                }
                if (listClickListener != null) {
                    listClickListener.onItemClick(v);
                }
            }
        });
    }
    public interface ListClickListener {
        void onItemClick(View view);
    }
    public List<String> getList() {
        List<String> list = new ArrayList<>();
        for (int i = 0; i < sparseArray.size(); i++) {
            int key = sparseArray.keyAt(i);
            list.add(sparseArray.get(key));
        }
        return list;

    }
}
